/**
 * Copyright(c) 2014 Xunton Solutions
 *
 * History:
 *   15-1-26 下午5:45 Created by dwzhang
 */
package com.jade.modules.cms;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

import org.apache.commons.lang3.StringUtils;

/**
 * 内容相关的统计数据。
 *
 * @author <a href="mailto:dwzhang@xunton.com">dwzhang</a> 
 * @version 1.0 15-1-26 下午5:45
 */
//@Entity
//@Table (name = "MODULE_CMS_CONTENT_COUNT")
public class ContentCount implements Serializable
{
    public static String TYPE_COMMENT = "comment";
    public static String TYPE_BROWSER = "browser";
    public static String TYPE_DOWNLOAD = "download";
    public static String TYPE_FAVORITE = "favorite";
    public static String TYPE_LIKE = "like";
    public static String TYPE_DISLIKE = "dislike";
    public static String TYPE_SCORE = "score";
    public static String TYPE_RESERVE1 = "reserve1";
    public static String TYPE_RESERVE2 = "reserve2";
    public static String[] TYPES = {TYPE_COMMENT, TYPE_BROWSER, TYPE_DOWNLOAD, TYPE_FAVORITE, TYPE_LIKE, TYPE_DISLIKE,
            TYPE_SCORE, TYPE_RESERVE1, TYPE_RESERVE2};

    //内容标识
    @Id
    @Column (name = "entity_type", length = 32)
    private String entityType;
    @Id
    @Column (name = "entity_id")
    private long entityId;
    //评论数量
    @Column (name = "comment_count")
    private long commentCount;
    //浏览数量
    @Column (name = "browser_count")
    private long browserCount;
    //下载数量
    @Column (name = "download_count")
    private long downloadCount;
    //收藏数量
    @Column (name = "favorite_count")
    private long favoriteCount;
    //点赞数量
    @Column (name = "like_count")
    private long likeCount;
    //不喜欢数量
    @Column (name = "dislike_count")
    private long dislikeCount;
    //分数,转化为总数100分
    @Column (name = "content_score")
    private long score;
    //保留字段
    @Column (name = "reserve1")
    private long reserve1;
    //保留字段
    @Column (name = "reserve2")
    private long reserve2;

    public String getEntityType()
    {
        return entityType;
    }

    public void setEntityType(String entityType)
    {
        this.entityType = entityType;
    }

    public long getEntityId()
    {
        return entityId;
    }

    public void setEntityId(long entityId)
    {
        this.entityId = entityId;
    }

    public long getCommentCount()
    {
        return commentCount;
    }

    public void setCommentCount(long commentCount)
    {
        this.commentCount = commentCount;
    }

    public long getBrowserCount()
    {
        return browserCount;
    }

    public void setBrowserCount(long browserCount)
    {
        this.browserCount = browserCount;
    }

    public long getFavoriteCount()
    {
        return favoriteCount;
    }

    public void setFavoriteCount(long favoriteCount)
    {
        favoriteCount = favoriteCount;
    }

    public long getDownloadCount()
    {
        return downloadCount;
    }

    public void setDownloadCount(long downloadCount)
    {
        this.downloadCount = downloadCount;
    }

    public long getLikeCount()
    {
        return likeCount;
    }

    public void setLikeCount(long likeCount)
    {
        this.likeCount = likeCount;
    }

    public long getDislikeCount()
    {
        return dislikeCount;
    }

    public void setDislikeCount(long dislikeCount)
    {
        this.dislikeCount = dislikeCount;
    }

    public long getScore()
    {
        return score;
    }

    public void setScore(long score)
    {
        this.score = score;
    }

    public long getReserve1()
    {
        return reserve1;
    }

    public void setReserve1(long reserve1)
    {
        this.reserve1 = reserve1;
    }

    public long getReserve2()
    {
        return reserve2;
    }

    public void setReserve2(long reserve2)
    {
        this.reserve2 = reserve2;
    }

    public void set(String type, long count)
    {
        if (StringUtils.equalsIgnoreCase(type, TYPE_COMMENT)) {
            setCommentCount(count);
        }
        else if (StringUtils.equalsIgnoreCase(type, TYPE_BROWSER)) {
            setBrowserCount(count);
        }
        else if (StringUtils.equalsIgnoreCase(type, TYPE_DOWNLOAD)) {
            setDownloadCount(count);
        }
        else if (StringUtils.equalsIgnoreCase(type, TYPE_FAVORITE)) {
            setFavoriteCount(count);
        }
        else if (StringUtils.equalsIgnoreCase(type, TYPE_LIKE)) {
            setLikeCount(count);
        }
        else if (StringUtils.equalsIgnoreCase(type, TYPE_DISLIKE)) {
            setDislikeCount(count);
        }
        else if (StringUtils.equalsIgnoreCase(type, TYPE_SCORE)) {
            setScore(count);
        }
        else if (StringUtils.equalsIgnoreCase(type, TYPE_RESERVE1)) {
            setReserve1(count);
        }
        else if (StringUtils.equalsIgnoreCase(type, TYPE_RESERVE2)) {
            setReserve2(count);
        }
    }

    public long get(String type)
    {
        if (StringUtils.equalsIgnoreCase(type, TYPE_COMMENT)) {
            return getCommentCount();
        }
        else if (StringUtils.equalsIgnoreCase(type, TYPE_BROWSER)) {
            return getBrowserCount();
        }
        else if (StringUtils.equalsIgnoreCase(type, TYPE_DOWNLOAD)) {
            return getDownloadCount();
        }
        else if (StringUtils.equalsIgnoreCase(type, TYPE_FAVORITE)) {
            return getFavoriteCount();
        }
        else if (StringUtils.equalsIgnoreCase(type, TYPE_LIKE)) {
            return getLikeCount();
        }
        else if (StringUtils.equalsIgnoreCase(type, TYPE_DISLIKE)) {
            return getDislikeCount();
        }
        else if (StringUtils.equalsIgnoreCase(type, TYPE_SCORE)) {
            return getScore();
        }
        else if (StringUtils.equalsIgnoreCase(type, TYPE_RESERVE1)) {
            return getReserve1();
        }
        else if (StringUtils.equalsIgnoreCase(type, TYPE_RESERVE2)) {
            return getReserve2();
        }
        return 0;
    }

    public boolean isAllZero()
    {
        return commentCount == 0 && browserCount == 0 && dislikeCount == 0 && likeCount == 0 &&
                favoriteCount == 0 && score == 0 && reserve1 == 0 && reserve2 == 0 && downloadCount == 0;
    }
}
